package com.kjtpay.design_pattern.interpreter;

/**
 * 表达式类，AbstractExpression
 */
abstract class Expression {
    // 解释之后的字符串
    protected String result;
    // 供外部获取解释之后的字符串
    public String getResult() {
        return result;
    }

    // 解释器
    public void interpret(PlayContext playContext) {
        if (null != playContext.playText) {
            String playKey = playContext.playText.substring(0, 1);
            playContext.playText = playContext.playText.substring(2);
            double playValue = Double.valueOf(playContext.playText.substring(0, playContext.playText.indexOf(" ")));
            playContext.playText = playContext.playText.substring(playContext.playText.indexOf(" ") + 1);

            execute(playKey, playValue);
        }
    }

    // 执行
    public abstract void execute(String key, double value);
}
